import com.chenshu.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

import javax.jws.soap.SOAPBinding;

/**
 * Created with IntelliJ IDEA
 * Description
 * com.chenshu.User：chenshu
 * Date：2023-12-11
 * Time：00:40
 */
public class  App {
    public static void main(String[] args) {
        //1.得到上下文对象

        //1.1
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");

        //2.2
        //BeanFactory context = new XmlBeanFactory(new ClassPathResource("spring-config.xml"));

        //2.取出bean对象
        
        //2.1根据id获取bean对象
        User user = (User) context.getBean("user1");
        System.out.println("user: " + user);

        User user1 = (User) context.getBean("user1");
        System.out.println("user1: " + user1);

        User user2 = (User) context.getBean("user2");
        System.out.println("user2: " + user2);

        System.out.println(user == user1);
        System.out.println(user == user2);
        //2.2 根据Class参数获取bean对象，在同类型的对象被注册到Spring中多次时，会报错
        //User user3 = context.getBean(User.class);

        //2.3  bean id + Class参数
        User user3 = context.getBean("user1", User.class);
        System.out.println("user3" + user3);

        //3.使用bean对象
        user.sayHi();
    }
}
